package com.demo.api.impl;

import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.demo.api.UserServiceApi;
import com.demo.entity.User;
import com.demo.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author ：qilong sun
 * @date ：Created in 2020/7/20 14:24
 * @description：
 * @modified By：
 * @version: V1.0$
 */
@DubboService
@Slf4j
public class UserServiceApiImpl implements UserServiceApi {
    @Autowired
    UserService userService;

   // @SentinelResource(blockHandler = "exceptionHandler")
    @Override
    public User getUser(Long uid) {
        User user = userService.getUser(uid);
        user.setName("我是sentinel-dubbo-user-provider-01");
        return user;
    }

    public User exceptionHandler(Long uid, BlockException e) {
        log.error("我这里是api实现类的exceptionHandler,我被限流了");
        return new User();
    }
}
